package com.dragon.modules.yuegou.enums;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 悦购小程序菜单
 * 
 * @author liuwu
 *
 */
public enum XcxMenu implements IMenu {

	/**
	 * 根节点
	 */
	ROOT(300, "悦购小程序", "root", 0),
	// 一级
	/**
	 * 首页动态菜单
	 */
	MAIN(302, "首页动态菜单", "main", 300),
	/**
	 * 个人中心动态菜单
	 */
	USER(303, "个人中心动态菜单", "user", 300),
	/**
	 * 营销菜单
	 */
	MARKETING(304, "营销菜单", "marketing", 300),
	// 二级
	// 首页动态菜单
	/** 优质好货 */
	MAIN_GOODS(310, "优质好货", "mainGoods", 302),
	/** 积分商城 */
	MAIN_SCORE_SHOP(311, "积分商城", "mainScoreShop", 302),
	/** 扫码支付 */
	MAIN_SCAN(312, "扫码支付", "mainScan", 302),
	/** 积分兑换 */
	MAIN_SCORE(313, "积分兑换", "mainScore", 302),
	/** 超值悦卡 */
	MAIN_HAPPY_CARD(314, "超值悦卡", "mainHappyCard", 302),
	/** 品牌悦店 */
	MAIN_SHOP(315, "品牌悦店", "mainShop", 302),
	/** 优惠停车 */
	MAIN_STOP_CAR(316, "优惠停车", "mainStopCar", 302),
	/** 精选套餐 */
	MAIN_SET_GOODS(317, "精选套餐", "mainSetGoods", 302),
	/** 商场服务 */
	MAIN_SERVICE(318, "商场服务", "mainService", 302),
	/** 抽奖服务 */
	MAIN_LOTTERY(319, "抽奖服务", "mainLottery", 302),
	/** 精选活动 */
	MAIN_FEATURED(350, "精选活动", "mainFeatured", 302),
	/** 精选活动 */
	MAIN_BROADCAST(351, "直播", "mainBroadcast", 302),
	// 个人中心动态菜单
	/** 我的钱包 */
	USER_WALLET(320, "我的钱包", "userWallet", 303),
	/** 我的订单 */
	USER_ORDER(321, "我的订单", "userOrder", 303),
	/** 我的停车 */
	USER_PARK(322, "我的停车", "userPark", 303),
	/** 交易记录 */
	USER_TRAD_RECORD(323, "交易记录", "userTradRecord", 303),
	/** 我的助力 */
	USER_HELP(324, "我的助力", "userHelp", 303),
	/** 消息 */
	USER_MSG(325, "消息", "userMsg", 303),
	/** 打卡 */
	USER_SIGN(326, "打卡", "userSign", 303),
	/** 修改资料 */
	USER_MODIFY(327, "修改资料", "userModify", 303),
	/** 粉丝关注 */
	USER_FANSCARE(328, "粉丝关注", "userFansCare", 303),
	/** 隐私设置 */
	USER_SETTING(329, "隐私设置", "userSetting", 303),
	/** 收藏 */
	USER_FAVORITE(330, "收藏", "userFavorite", 303),
	/** 安全中心 */
	USER_SAFE_CENTER(331, "安全中心", "userSafeCenter", 303),
	/** 退出登录 */
	USER_LOGOUT(332, "退出登录", "userLogout", 303),
	/** 我的拼团 */
	USER_GROUPN(333, "我的拼团 ", "userGroupn", 303),
	/** 会员福利 */
	USER_WALFARE(334, "会员福利", "userWelfare", 303),
	/** 购物车 */
	USER_SHOPPING(335, "购物车 ", "userShopping", 303),
	/** 举报 */
	USER_REPORT(336, "举报 ", "userReport", 303),
	/** 红包卡券 */
	USER_CARD_VOUCHER(337, "红包卡券", "userCardVoucher", 303),
	// 营销菜单
	/** 秒杀 */
	ACTIVITY_SECONDS_KILL(340, "秒杀", "activitySecondsKill", 304),
	/** 助力 */
	ACTIVITY_HELP(341, "助力", "activityHelp", 304),
	/** 限时抢购 */
	ACTIVITY_TIME_LIMIT(342, "限时抢购", "activityTimeLimit", 304),

	/** 收货地址 */
	SHIPPING(345, "收货地址", "shipping", 303),

	/** 积分签到 */
	MAIN_SIGN(344, "积分签到", "mainSign", 302);

	/**
	 * 菜单ID
	 */
	private int id;

	/**
	 * 菜单别名（中文名，展示给用户看的名称）
	 */
	private String alias;

	/**
	 * 菜单路径（菜单标识，并不对应接口路径）
	 */
	private String path;

	/**
	 * 父菜单ID，0表示没有父菜单
	 */
	private int parentId;

	private XcxMenu(int id, String alias, String path, int parentId) {
		this.id = id;
		this.alias = alias;
		this.path = path;
		this.parentId = parentId;
	}

	@Override
	public int getId() {
		return id;
	}

	@Override
	public String getAlias() {
		return alias;
	}

	@Override
	public String getPath() {
		return path;
	}

	@Override
	public int getParentId() {
		return parentId;
	}

	/**
	 * 根据路径获取菜单
	 * 
	 * @param path 菜单路径（标识）
	 * @return 菜单
	 */
	@Nullable
	public static XcxMenu from(String path) {
		if (path == null) {
			return null;
		}
		return PATH_MAP.get(path);
	}

	/**
	 * Path Map for Menu
	 */
	private static final Map<String, XcxMenu> PATH_MAP = Stream.of(XcxMenu.values())
			.collect(Collectors.toMap(XcxMenu::getPath, UnaryOperator.identity()));

}
